import { loadUsersJson,saveUser,deleteUser,editUserInfoNew,resetUserPassword} from '@/services/geographic';
import { queryCurrent,addRole,getRoleList,updateRole,delRole,getRoleByRoleId,getRolesByCreateUserPage} from '@/services/user';
export default {
  namespace:'roleManagement',
  state: {
    total:0,
    items:[],
    loading:true
  },
  effects: {
    *getRoleLists({ payload, callback }, { call, put }) {
      const response = yield call(getRolesByCreateUserPage, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *addRoles({ payload, callback }, { call, put }) {
      const response = yield call(addRole, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *updateRoles({ payload, callback }, { call, put }) {
      const response = yield call(updateRole, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *resetUser({ payload, callback }, { call, put }) {
      const response = yield call(resetUserPassword, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *delRoles({ payload, callback }, { call, put }) {
      const response = yield call(delRole, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *getRoleByRoleIds({ payload, callback }, { call, put }) {
      const response = yield call(getRoleByRoleId, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
